<?php


namespace app\common\validate;


use think\Validate;

class AgentLethouseValidate extends Validate {

    protected $rule =   [
        'qu_id'             => 'require|number',
        'housestyledetail'  => 'require',
        'salestatus'        => 'require',
        'decorate'          => 'require',
        'direction'         => 'require',
        'lat'               => 'require',
        'lng'               => 'require',
        'address'           => 'require',
        'title'             => 'require',
        'unit_price'        => 'require',
        'area'              => 'require',
        'floor'             => 'require',
        'year'              => 'require',
        'housetype'         => 'require',
        'special'           => 'require|checkSpecialArrayLength',
        'peitao'            => 'require|checkPeitaoArrayLength',
        'content'           => 'require',
        'thumbs'            => 'require|checkThumbsArrayLength',
    ];

    protected $message  =   [
        'qu_id.require'             => '请选择区域',
        'qu_id.number'              => '数据格式有误，请联系管理员',
        'housestyledetail.require'  => '请选择户型',
        'salestatus.require'        => '请选择出租方式',
        'decorate.require'          => '请选择装修',
        'direction.require'         => '请选择方向',
        'lat.require'               => '请选择位置',
        'lng.require'               => '请选择位置',
        'address.require'           => '请输入地址',
        'title.require'             => '请输入房源标题',
        'unit_price.require'        => '请输入售价',
        'area.require'              => '请输入面积',
        'floor.require'             => '请输入楼层',
        'year.require'              => '请输入年代',
        'housetype.require'         => '请选择房源类型',
        'special.require'           => '请选择房源特色',
        'peitao.require'            => '请选择配套',
        'content.require'           => '请输入详情',
        'thumbs.require'            => '请上传房源图片',
    ];


    protected function checkPeitaoArrayLength($value, $rule, $data=[]){
        if(!is_array($data['peitao'])){
            return '数据格式有误，请联系管理员';
        }
        if(sizeof($data['peitao'])==0){
            return '请选择房源配套';
        }
        return  true;
    }

    protected function checkSpecialArrayLength($value, $rule, $data=[]){
        if(!is_array($data['special'])){
            return '数据格式有误，请联系管理员';
        }
        if(sizeof($data['special'])==0){
            return '请选择房源特色';
        }
        return  true;
    }

    protected function checkThumbsArrayLength($value, $rule, $data=[]){
        if(!is_array($data['thumbs'])){
            return '数据格式有误，请联系管理员';
        }
        if(sizeof($data['thumbs'])==0){
            return '请上传房源图片';
        }
        return  true;
    }


}